#include "MarsPrecompile.h"
#include "MarsMeshTriangle.h"
#include "MarsInputLayout.h"
#include "MarsVertexData.h"

using namespace Graphics;

typedef struct
{
	XMFLOAT3 Pos;
	XMFLOAT2 TexCoord;
} Vertex;

bool MeshTriangle::Load()
{
	InputLayout* pInputLayout = new InputLayout();
	pInputLayout->AddElement( "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 );
	pInputLayout->AddElement( "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, sizeof(XMFLOAT3), D3D11_INPUT_PER_VERTEX_DATA, 0 );

	Vertex* vertices = new Vertex[ 6 ];
	vertices[ 0 ].Pos	   = XMFLOAT3(  1.0f,  1.0f, 1.0f );
	vertices[ 0 ].TexCoord = XMFLOAT2(  1.0f,  1.0f );
	vertices[ 1 ].Pos	   = XMFLOAT3(  1.0f, -1.0f, 1.0f );
	vertices[ 1 ].TexCoord = XMFLOAT2(  1.0f,  0.0f );
	vertices[ 2 ].Pos	   = XMFLOAT3( -1.0f, -1.0f, 1.0f );
	vertices[ 2 ].TexCoord = XMFLOAT2(  0.0f,  0.0f );
	vertices[ 3 ].Pos	   = XMFLOAT3( -1.0f, -1.0f, 1.0f );
	vertices[ 3 ].TexCoord = XMFLOAT2(  0.0f,  0.0f );
	vertices[ 4 ].Pos	   = XMFLOAT3( -1.0f,  1.0f, 1.0f );
	vertices[ 4 ].TexCoord = XMFLOAT2(  0.0f,  1.0f );
	vertices[ 5 ].Pos	   = XMFLOAT3(  1.0f,  1.0f, 1.0f );
	vertices[ 5 ].TexCoord = XMFLOAT2(  1.0f,  1.0f );

	m_pVertexData = new VertexData( pInputLayout, ( uint8* ) vertices, sizeof( Vertex ) * 6 );
	m_eTopology = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;

	m_iVertexCount = 6;
	m_iStride = sizeof( Vertex );
	m_iOffset = 0;

	return true;
}
